<?php
namespace app\index\controller;
use app\common\exception\System as SystemException;
use app\index\model\Friend;
use think\Db;

class Friends extends Common
{
    /**
   * 不需要登录
   * @var array
   */
  protected $noNeedLogin = ['*'];
	public function details()
	{
    $id=$this->request->param('id');
    $res = Friend::with('Members')->where("id",$id)->find();
    if($res){
      $arr=['status'=>1,'data'=>$res,'msg'=>'获取成功'];
      return $this->successReturn($arr,SystemException::E_SUCCESS, $arr['msg']); 
    }else{
      $arr=['status'=>0,'msg'=>'获取失败'];
      return $this->successReturn($arr,SystemException::E_SUCCESS, $arr['msg']);      
    }
	}
  public function add()
  {
    $data=$this->request->param();
    $data['member_id']=$this->auth->member_id;
    $model = new \app\index\model\Friend;
    $res=$model->allowField(true)->save($data);
    if($res){
      $arr=['status'=>1,'msg'=>'提交成功'];
      return $this->successReturn($arr,SystemException::E_SUCCESS, $arr['msg']); 
    }else{
      $arr=['status'=>0,'msg'=>'提交失败'];
      return $this->successReturn($arr,SystemException::E_SUCCESS, $arr['msg']);      
    }
  }
}
